package com.runfast.waimai.service.impl;

import com.runfast.common.service.BaseService;
import com.runfast.waimai.dao.model.*;
import com.runfast.waimai.service.RunfastGoodsSellOptionService;
import com.runfast.waimai.service.RunfastGoodsSellSubOptionService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class RunfastGoodsSellOptionServiceImpl extends BaseService<RunfastGoodsSellOption, Integer, RunfastGoodsSellOptionExample> implements RunfastGoodsSellOptionService {
    @Autowired
    private RunfastGoodsSellOptionService runfastGoodsSellOptionService;
    @Autowired
    private RunfastGoodsSellSubOptionService runfastGoodsSellSubOptionService;
    public void saveOPtionsAndSubOptions(RunfastGoodsSell t){
        //循环保存选项
        if(t.getOptionList().size()>0){
                for(RunfastGoodsSellOption option:t.getOptionList()){
                    if(option!=null && StringUtils.isNotBlank(option.getName())){
                        RunfastGoodsSellOption goodsSellOption=new RunfastGoodsSellOption();
                        goodsSellOption.setName(option.getName());
                        goodsSellOption.setBusinessid(t.getBusinessid());
                        goodsSellOption.setBusinessname(t.getBusinessname());
                        goodsSellOption.setGoodssellid(t.getId());
                        goodsSellOption.setGoodssellname(t.getName());
                        goodsSellOption.setDeleted(false);
                        runfastGoodsSellOptionService.insertSelective(goodsSellOption);
                        if(option.getSellSubOptionList().size()>0){
                            for(RunfastGoodsSellSubOption s:option.getSellSubOptionList()){
                                if(s!=null && StringUtils.isNotBlank(s.getName())){
                                    RunfastGoodsSellSubOption subOption=new RunfastGoodsSellSubOption();
                                    subOption.setName(s.getName());
                                    subOption.setBusinessid(t.getBusinessid());
                                    subOption.setBusinessname(t.getBusinessname());
                                    subOption.setGoodssellid(t.getId());
                                    subOption.setGoodssellname(t.getName());
                                    subOption.setOptionid(goodsSellOption.getId());
                                    subOption.setOptionname(goodsSellOption.getName());
                                    subOption.setDel(0);
                                    runfastGoodsSellSubOptionService.insertSelective(subOption);
                                }
                            }
                        }
                    }
            }
        }
    }
}